package com.competitions.videoedithelper.utils;

import java.io.File;
import java.util.Random;

/**
 * @author 盛旭雯
 */
public class FileUtil {
    public static void deleteFiles(File[] files){
        boolean isDeleteSuccess=true;
        for (File file:files){
            if(file!=null){
                if (file.exists()){
                    isDeleteSuccess=file.delete();
                }
            }
        }
        if(!isDeleteSuccess){
            System.out.println("删除文件失败");
        }
    }

    public static void deleteFile(File file){
        boolean isDeleteSuccess=true;
        if(file!=null){
            if (file.exists()){
                isDeleteSuccess=file.delete();
            }
        }
        if(!isDeleteSuccess){
            System.out.println("删除文件失败");
        }
    }

    public static String getId(int length){
        StringBuilder stringBuilder = new StringBuilder();
        Random random = new Random();
        for (int x = 0; x < length; x++) {
            stringBuilder.append(random.nextInt(10));
        }
        return stringBuilder.toString();
    }

    public static boolean createFolder(String filePathDir){
        File saveFileDir=new File(filePathDir);
        if (!saveFileDir.exists()) {
            if (!saveFileDir.mkdirs()){
                System.out.println("创建文件夹失败");
                return false;
            }
        }
       return true;
    }
}
